package com.ruoyi.common.core.utils;

public class OSUtils {
    private OSUtils() {
        // 工具类，防止实例化
    }

    public static boolean isWindows() {
        return getOSName().contains("win");
    }

    public static boolean isMac() {
        return getOSName().contains("mac");
    }

    public static boolean isLinux() {
        return getOSName().contains("nix") ||
                getOSName().contains("nux") ||
                getOSName().contains("aix");
    }

    public static boolean isUnix() {
        return isLinux() ||
                getOSName().contains("sunos") ||
                getOSName().contains("bsd");
    }

    public static boolean isSolaris() {
        return getOSName().contains("sunos");
    }

    public static String getOSName() {
        return System.getProperty("os.name").toLowerCase();
    }

    public static String getOSVersion() {
        return System.getProperty("os.version");
    }

    public static String getOSArch() {
        return System.getProperty("os.arch");
    }

    public static String getDetailedOSInfo() {
        return String.format("OS: %s, Version: %s, Arch: %s",
                getOSName(), getOSVersion(), getOSArch());
    }

    public static OSType getOSType() {
        String osName = getOSName();

        if (osName.contains("win")) {
            return OSType.WINDOWS;
        } else if (osName.contains("mac")) {
            return OSType.MAC;
        } else if (osName.contains("nix") || osName.contains("nux")) {
            return OSType.LINUX;
        } else if (osName.contains("sunos")) {
            return OSType.SOLARIS;
        } else {
            return OSType.UNKNOWN;
        }
    }

    public enum OSType {
        WINDOWS, MAC, LINUX, SOLARIS, UNKNOWN
    }
}
